﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_rm_order_details
{
    public DAL_tbl_rm_order_details()
    {

    }



    public List<tbl_rm_order_details> select(int RM_DETAILS_ID)
    {
        List<tbl_rm_order_details> list = new List<tbl_rm_order_details>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select RM_DETAILS_ID,RM_ORDER_ID,RAW_MATERIAL_ID,QUANTITY_IN_KG,PRICE_PER_KG,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_rm_order_details where RM_DETAILS_ID=@RM_DETAILS_ID";
        cmd.Parameters.AddWithValue("@RM_DETAILS_ID", RM_DETAILS_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_rm_order_details()
            {
                RM_DETAILS_ID = Convert.ToInt32(dr["RM_DETAILS_ID"]),
                RM_ORDER_ID = Convert.ToInt32(dr["RM_ORDER_ID"]),
                RAW_MATERIAL_ID = Convert.ToInt32(dr["RAW_MATERIAL_ID"]),
                QUANTITY_IN_KG = Convert.ToDecimal(dr["QUANTITY_IN_KG"]),
                PRICE_PER_KG = Convert.ToDecimal(dr["PRICE_PER_KG"]),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_rm_order_details> selectAll()
    {
        List<tbl_rm_order_details> list = new List<tbl_rm_order_details>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select RM_DETAILS_ID,RM_ORDER_ID,RAW_MATERIAL_ID,QUANTITY_IN_KG,PRICE_PER_KG,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_rm_order_details Order By RM_DETAILS_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_rm_order_details()
            {
                RM_DETAILS_ID = Convert.ToInt32(dr["RM_DETAILS_ID"]),
                RM_ORDER_ID = Convert.ToInt32(dr["RM_ORDER_ID"]),
                RAW_MATERIAL_ID = Convert.ToInt32(dr["RAW_MATERIAL_ID"]),
                QUANTITY_IN_KG = Convert.ToDecimal(dr["QUANTITY_IN_KG"]),
                PRICE_PER_KG = Convert.ToDecimal(dr["PRICE_PER_KG"]),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(int RM_ORDER_ID, int RAW_MATERIAL_ID, Decimal QUANTITY_IN_KG, Decimal PRICE_PER_KG, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_rm_order_details(RM_ORDER_ID, RAW_MATERIAL_ID, QUANTITY_IN_KG, PRICE_PER_KG, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@RM_ORDER_ID, @RAW_MATERIAL_ID, @QUANTITY_IN_KG, @PRICE_PER_KG, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@RM_ORDER_ID", RM_ORDER_ID);
        cmd.Parameters.AddWithValue("@RAW_MATERIAL_ID", RAW_MATERIAL_ID);
        cmd.Parameters.AddWithValue("@QUANTITY_IN_KG", QUANTITY_IN_KG);
        cmd.Parameters.AddWithValue("@PRICE_PER_KG", PRICE_PER_KG);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int RM_DETAILS_ID, int RM_ORDER_ID, int RAW_MATERIAL_ID, Decimal QUANTITY_IN_KG, Decimal PRICE_PER_KG, bool IS_ACTIVE, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_rm_order_details SET RM_ORDER_ID=@RM_ORDER_ID, RAW_MATERIAL_ID=@RAW_MATERIAL_ID, QUANTITY_IN_KG=@QUANTITY_IN_KG, PRICE_PER_KG=@PRICE_PER_KG, IS_ACTIVE=@IS_ACTIVE, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE RM_DETAILS_ID=@RM_DETAILS_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@RM_DETAILS_ID", RM_DETAILS_ID);
        cmd.Parameters.AddWithValue("@RM_ORDER_ID", RM_ORDER_ID);
        cmd.Parameters.AddWithValue("@RAW_MATERIAL_ID", RAW_MATERIAL_ID);
        cmd.Parameters.AddWithValue("@QUANTITY_IN_KG", QUANTITY_IN_KG);
        cmd.Parameters.AddWithValue("@PRICE_PER_KG", PRICE_PER_KG);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int RM_DETAILS_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_rm_order_details WHERE RM_DETAILS_ID=@RM_DETAILS_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@RM_DETAILS_ID", RM_DETAILS_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}